import datetime

N=input()
year=N[:4]
month_in=N[4:6]
day_in=N[6:]
date_in=datetime.date(int(year),int(month_in),int(day_in))

def find_next_date(year):
    if int(year) > 8290:
        return 'None'
    if int(year) == 8290:
        if int(N[4:]) >= 928:
            return 'None'
        else:
            return '82900928'
    try:
        year_out=int(year)
        month_out=int(year[3]+year[2])
        day_out=int(year[1]+year[0])
        date_out=datetime.date(year_out,month_out,day_out)
        if date_out > date_in:
            return str(date_out).replace('-','')
        else:
            return find_next_date(('000'+str(int(year)+1))[-4:])
    except Exception:
        return find_next_date(('000'+str(int(year)+1))[-4:])

print(find_next_date(year))

dates=[1011010,10100101,20200202,21211212,30300303,
       40400404,50500505,60600606,70700707,80800808]

if int(N) > dates[-1]:
    print('None')
else:
    for date in dates:
        if date > int(N):
            print(('0'+str(date))[-8:])
            break
